﻿using B.S.Ingredients.APIRead.Application.Command.SlanBoss;
using B.S.Ingredients.Domain;
using B.S.Ingredients.ErrorCode;
using B.S.Ingredients.Infartructrue.Interfaces;
using MediatR;
using Microsoft.EntityFrameworkCore.Storage.Json;
using System.Text.Json.Serialization;

namespace B.S.Ingredients.APIRead.Application.CommandHandler.SlanBossHandler
{
    public class BossFtCommandHandler : IRequestHandler<BossFtCommand, APIResult<SlanghterBoss>>
    {
        public BossFtCommandHandler(IBaseRepository<SlanghterBoss> bossRepository)
        {
            BossRepository = bossRepository;
        }

        public IBaseRepository<SlanghterBoss> BossRepository { get; }

        public async Task<APIResult<SlanghterBoss>> Handle(BossFtCommand request, CancellationToken cancellationToken)
        {
            var path = BossRepository.GetAll().FirstOrDefault(a => a.Productuins == request.Productuins);
            
            return new APIResult<SlanghterBoss>
            {
                Code = ResultCode.success,
                Mag = "",
                Data = path
            };
        }
    }
}
